import store from '@/store/index';

// 定义角色验证规则
function verityRole(list = []) {
  const roles = store?.getters['user/roleMarkSet'];

  if (list?.length > 0) {
    const hasRole = list.some((item) => {
      return roles.has(item);
    });

    return hasRole;
  }
}

// 定义角色权限指令
const RoleDirective = {
  inserted(el, binging, vnode) {
    const hasRole = verityRole(binging?.value);
    if (!hasRole) {
      el?.parentNode?.removeChild(el);
    }
  }
};

export default RoleDirective;
